package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.SettingsMapper;
import com.tanhua.model.domain.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    SettingsMapper mapper;

    @Override
    public Settings findByUserId(Long userId) {
        QueryWrapper<Settings> settingsQueryWrapper = new QueryWrapper<>();
        settingsQueryWrapper.eq("user_id", userId);
        try {
            Settings settings = mapper.selectOne(settingsQueryWrapper);
            return settings;
        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }

    @Override
    public void insert(Settings settings) {
        mapper.insert(settings);
    }

    @Override
    public void update(Settings settings) {
        mapper.updateById(settings);
    }
}
